/**
 * Created with IntelliJ IDEA.
 * Description:二分查找
 * User: wangxin
 * Date: 2024-10-31
 * Time: 21:31
 */
public class test2 {
    public int search (int[] nums, int target) {
        // write code here
        int left = 0;
        int right = nums.length - 1;
        while( left <= right){
            int n = (left + right) / 2;
            if(nums[n] == target){
                return n;
            }
            if(nums[n] < target){
                left = n + 1;
            }else{
                right = n - 1;
            }
        }
       
        return -1;
    }
}
